# -*- coding:UTF-8 -*-
import time

import pyautogui

import keyboard
import math


def get_pos():
    while True:
        print(pyautogui.position())
        time.sleep(1)


def GetCurPos(index):
    x, y = pyautogui.position()
    print(f"point_{index}:({x},{y})")
    return [x, y]


def CalAngle(A, O, B):
    print(f"A:{A},O:{O}, B:{B}")
    line_AO2 = pow(A[0] - O[0], 2) + pow(A[1] - O[1], 2)
    line_BO2 = pow(B[0] - O[0], 2) + pow(B[1] - O[1], 2)
    line_AB2 = pow(B[0] - A[0], 2) + pow(B[1] - A[1], 2)
    cos_th = (line_AO2 + line_BO2 - line_AB2) / (2 * math.sqrt(line_AO2) * math.sqrt(line_BO2))
    result = math.acos(cos_th) / math.pi * 180
    print("=============================|")
    print("=========================角度:|==>{:.2f}".format(result))
    print("=============================|")


def GetAnglePoint():
    print("把鼠标放在第1个点并按a键 [x][][]")
    keyboard.wait('a')
    pos_a = GetCurPos(1)
    pos_o = pos_a

    while pos_o == pos_a:
        print("把鼠标放在第2个点并按a键 [x][x][]")
        keyboard.wait('a')
        pos_o = GetCurPos(2)

    pos_b = pos_o
    while pos_b == pos_a or pos_b == pos_o:
        print("把鼠标放在第3个点并按a键 [x][x][x]")
        keyboard.wait('a')
        pos_b = GetCurPos(3)
    return pos_a, pos_o, pos_b


def Run():
    print("=====开始运行屏幕量角器:=====")
    CalAngle(*GetAnglePoint())


if __name__ == '__main__':
    while True:
        Run()
